package com.zhi.web.controller.consumer;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.extra.mail.MailAccount;
import cn.hutool.extra.mail.MailUtil;
import com.alibaba.fastjson.JSON;
import com.zhi.common.utils.email.MailUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import static com.zhi.common.constant.blog.MQPrefixConst.EMAIL_EXCHANGE;
import static com.zhi.common.constant.blog.MQPrefixConst.EMAIL_QUEUE;
import com.zhi.system.dto.EmailDTO;
/**
 * 通知邮箱
 *
 * @author water-zhi
 * @date 2021/06/13
 * @since 1.0.0
 **/
@Slf4j
@Component
@RabbitListener(bindings = @QueueBinding(
    value = @Queue(EMAIL_QUEUE),
    exchange = @Exchange(EMAIL_EXCHANGE)
))
public class EmailConsumer {

    @RabbitHandler
    public void process(byte[] data) {

        EmailDTO emailDTO = JSON.parseObject(new String(data), EmailDTO.class);
        log.info(emailDTO.toString());
        MailUtils.sendText(emailDTO.getEmail(),emailDTO.getSubject(),emailDTO.getContent());
    }

}
